﻿#include<vector>
#include <iostream>
#include <algorithm>
using namespace std;

int rob(vector<int>& nums) {
    if (nums.empty()) {
        return 0;
    }
    int size = nums.size();
    if (size == 1)return nums[0];
    vector<int> res = vector<int>(size, 0);
    res[0] = nums[0];
    res[1] = max(nums[0], nums[1]);
    for (int i = 2; i < size; i++) {
        res[i] = max(res[i - 2] + nums[i], res[i - 1]);
    }
    return res[size - 1];
}




